import urllib.request

url = "https://www.cnblogs.com/anpengapple/p/8051923.html"
req = urllib.request.Request(url)
req.add_header("User-Agent" ,"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36")
data = urllib.request.urlopen(req).read()
file = open("C:/Users/will.mao/Desktop/爬虫demo/TestAddHeaders.html","wb")
print(urllib.request.urlopen(req).getcode())
file.write(data)